/*
 * JTextFieldWithIcon.java
 *
 * Created on August 27, 2007, 4:20 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package com.afaker.rss.gui;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.TexturePaint;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.JTextField;

/**
 *
 * @author bruce
 */
public class JTextFieldWithIcon extends JTextField{
    private BufferedImage img;
    private TexturePaint texture;
    private Graphics g;
    private static final int LEFT = 1;
    private static final int RIGNT = 2;
    private int position = 1;
    private boolean iconVisible = false;
    /** Creates a new instance of JTextFieldWithIcon */
    public JTextFieldWithIcon(File imageFile) throws IOException {
        super();
        img = ImageIO.read(imageFile);        
    }
    
    public void setPosition(int position) {
        this.position = position;
        //repaint();
    }
    
    public void paintComponent(Graphics g) {
        this.g = g;
        int x;
        int rectX;
        if(iconVisible){
            setOpaque(false);
            if(position == LEFT)
            {
                x = 0;
                rectX = img.getWidth();
            }
            else
            {
                x = getWidth() - img.getWidth();
                rectX = 0;
            }
            g.drawImage(img,x + 1,1,img.getWidth(),getHeight(),null,null);
            g.setColor(new Color(255,255,255));
            g.fillRect(rectX,1,getWidth() + img.getWidth() - rectX ,getHeight());
        }
        super.paintComponent(g);
    }
    
    public void draw() {
        iconVisible = true;
        repaint();
    }


    
}
